package com.damai.action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.citywithincity.db.Db;
import com.citywithincity.models.Models;

public abstract class BaseServiceAction implements IAction {
	
	private String key;
	
	public BaseServiceAction(String key){
		this.key = key;
		try {
			Models.assignModels(this);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	
	public abstract void execute(HttpServletRequest request, HttpServletResponse response) throws IOException;
	
	@Override
	public void doFilter(HttpServletRequest request, HttpServletResponse response) throws IOException {
		try{
			execute(request, response);
		}finally{
			Db.release();
		}
	}

	
	@Override
	public String getKey(){
		return key;
	}
}
